package com.zhijian.warehouse.manage.entity.export;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.zhijian.util.BeanUtil;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 影响库存操作记录表 回显vo
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-28 10:28:44
 */
@Data
public class StoreOptRecordExport {

    @Excel(name = "序号", format = "isAddIndex")
    private Integer serial;

    @Excel(name = "出入库单号", width = 20)
    private String voucherCode;

    @Excel(name = "出入库类型",
            replace = {"产品入库_1", "产品出库_2", "盘盈入库_3", "盘亏出库_4", "调拨入库_5", "调拨出库_6", " _null"})
    private Integer optType;

    @Excel(name = "产品名称")
    private String productName;

    @Excel(name = "出入库时间")
    private String createTimeStr;

    @Excel(name = "产品编号", width = 20)
    private String productNumber;

    @Excel(name = "产品类型")
    private String categoryName;

    @Excel(name = "规格", width = 20)
    private String productModel;

    @Excel(name = "单位")
    private String unitName;

    @Excel(name = "仓库")
    private String warehouseName;

    @Excel(name = "库位")
    private String warehouseLocationName;

    @Excel(name = "产品RFID", width = 30)
    private String productRfId;

    @Excel(name = "入库数量")
    private String inCount;

    @Excel(name = "出库数量")
    private String outCount;
    @Excel(name = "出库时间")
    private String outTime;
    @Excel(name = "出库说明")
    private String purpose;
    @Excel(name = "出库领用人")
    private String drawUserName;
    @Excel(name = "制单人")
    private String crtUserName;

    @Excel(name = "制单时间", width = 20)
    private String voucherTime;

    @Excel(name = "审核人")
    private String optUserName;

    @Excel(name = "审核时间", width = 30)
    private String createTime;
    /**
     * 数量类型 1=入库 2=出库
     */
    private Integer type;

    /**
     * 数量绝对值
     */
    private BigDecimal count;

    /**
     * 单位小数位
     */
    private Integer unitFraction;

    public String getInCount() {
        if (BeanUtil.isNotEmpty(this.type) && this.type == 1)
            return initData(this.count).toString();
        return BigDecimal.ZERO.toString();
    }

    public String getOutCount() {
        if (BeanUtil.isNotEmpty(this.type) && this.type == -1)
            return initData(this.count).toString();
        return BigDecimal.ZERO.toString();
    }

    //初始化 数据 如果不是空的则补全小数位
    public BigDecimal initData(BigDecimal data) {
        if (data == null) {
            return BigDecimal.ZERO;
        }
        if (BeanUtil.isEmpty(this.unitFraction))
            return data;
        return data.setScale(this.unitFraction, RoundingMode.HALF_UP);
    }
}
